package dev.pda.display.presentation.page.widgets

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import android.util.TypedValue
import android.view.ViewGroup
import android.webkit.WebView
import android.webkit.WebViewClient
import android.widget.LinearLayout
import android.widget.TextView
import dev.pda.display.presentation.page.model.widget.TextWidget

class CustomTextView : LinearLayout {

    private var textView: TextView? = null

    companion object {
        private const val HTTP = "http"
        private const val HTTPS = "https://"
    }

    constructor(context: Context?) : super(context) {
        init(null)
    }

    constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {
        init(attrs)
    }

    @SuppressLint("SetJavaScriptEnabled")
    private fun init(attrs: AttributeSet?) {
        textView = TextView(context)

        this.addView(textView)
    }

    fun setTextMethod(widget: TextWidget) {
        textView?.apply {
            text = widget.item?.content
            setSingleLine(true)
            textSize = TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_PX,
                widget.item?.fontSize?.toFloat() ?: 16f,
                context.resources.displayMetrics
            )
            setTextColor(Color.parseColor(widget.item?.fontColor))
        }
    }
}